#!/usr/bin/env python
#coding: utf-8
'''
Created on 2017年4月17日

@author: Administrator
'''
from django.contrib import admin

from comment.models import Comment

class CommentAdmin(admin.ModelAdmin):
    list_display = ('user', 'object_id', 'text_content', 'floor', 'state', 'create_time')
    raw_id_fields = ('user', 'parent')
    search_fields = ('user__username',)
    list_filter = ('state', 'content_type')
    list_per_page = 20
    readonly_fields = ('create_time', 'modify_time')
    
    def queryset(self, request):
        qs = self.model._default_manager.get_query_set().select_related('user')
        if request.path == '/admin/comment/comment/':
            qs = qs.only('id', 'user__username', 'object_id', 'text_content', 'floor', 'state', 'create_time')
        # TODO: this should be handled by some parameter to the ChangeList.
        ordering = self.get_ordering(request)
        if ordering:
            qs = qs.order_by(*ordering)
        return qs

admin.site.register(Comment, CommentAdmin)
